<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item v-if="$route.path=='/loanlists'">{{$t('sidebar.business')}}</el-breadcrumb-item>
        <el-breadcrumb-item v-else>{{$t('newcrumbs.crumbsOne')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('loanMoney.crumbsThr')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- -------------搜索查询栏------------------------ -->
    <search 
			:searchData="searchData" 
			@search="search" 
			@putExcel="putExcel" 
			:searchRight="true"
			:outputRight="$store.state.common.permiss[routename].includes('export')"
    ></search>

    <!-- -------------表单显示栏------------------------ -->
    <div class="table">
      <template>
        <el-table :data="tableData" size="small" stripe empty-text v-loading="loadFlag">
          <el-table-column align="center" prop="id" :label="$t('public.orderId')" >
          </el-table-column>
          <el-table-column align="center" prop="userId" :label="$t('public.userId')" >
          </el-table-column>
          <el-table-column align="center" prop="userName" :label="$t('public.name')" >
          </el-table-column>
          <el-table-column align="center" prop="userPhone" :label="$t('public.userTel')" >
          </el-table-column>
          <el-table-column align="center" prop="loanAmount" :label="$t('public.no30')" >
            <template slot-scope="scope">
              <span>{{$store.state.common.id_currency}}{{$store.getters.moneySplit(scope.row.loanAmount)}}{{$store.state.common.vi_currency}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="productPeriod" :label="$t('public.no31')+'('+$t('public.no26')+')'" >
          </el-table-column>
          <el-table-column align="center" prop="createTime" :label="$t('public.CreateDate')" width="120">
          </el-table-column>
          <el-table-column align="center" prop="status" :label="$t('public.orderStatus')" >
            <template slot-scope="scope">
              <span>{{$t($store.getters.rejectStatus(scope.row.status))}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="user.regDevice" :label="$t('add.no7')">
            <template slot-scope="scope">
              <span>{{$t($store.getters.clientStatus(scope.row.user.regDevice))}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="user.regChannel" :label="$t('public.registerChannel')">
          </el-table-column>
          <el-table-column align="center" prop="product.appName" :label="$t('public.appName')">
          </el-table-column>
          <el-table-column align="center" prop="product.appPackage" :label="$t('public.appPackage')">
          </el-table-column>
          
          <el-table-column fixed="right" align="center" prop="operation" :label="$t('public.operation')" min-width="160">
            <template slot-scope="scope">
              <span v-if="$store.state.common.permiss[routename].includes('view')"      
                class="table_opr"
                @click="loanDetali(scope.row.id,scope.row.userId)">
                {{$t('public.detail')}}
              </span>
              <!-- <span v-if="$store.state.common.permiss[routename].includes('download')"
                class="table_opr" 
                @click="download(scope.row.contractPath)">
                {{$t('public.no52')}}
              </span> -->
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>

    <!-- ------------  分页显示栏  ------------------------ -->
    <el-row type="flex" justify="end">
      <div class="pages" >
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          layout="sizes, prev, pager, next, total,->"
          :page-sizes="pagination.pageSizeOptions"
          :page-size="pagination.pageSize"
          @size-change="handleSizeChange"
          :total="pagination.total">
        </el-pagination>
      </div>
    </el-row>
    <div class="foot"></div>
  </div>
</template>
<script>
import putExcel from 'src/mixins/putExcel.js';//导出excel
import getApp from 'src/mixins/getApp.js';//获取app和aok
import getChannel from 'src/mixins/getChannel.js';//获取渠道数据
import getMerchant from 'src/mixins/getMerchant.js';
export default {
  name: 'loanMoneyList',
  mixins:[putExcel,getApp,getChannel,getMerchant],
  data() {
    const searchData=[
      {
        type: 'input',
        label: 'public.orderId',
        attr: 'id',
        value: ''
      },
      {
        type: 'input',
        label: 'public.userId',
        attr: 'userId',
        value: ''
      },
      {
        type: 'input',
        label: 'public.name',
        attr: 'userName',
        value: ''
      },
      {
        type: 'input',
        label: 'public.userPhone',
        attr: 'userPhone',
        value: ''
      },{
        type: 'select',
        attr: 'status',
        label: 'public.orderStatus',
        option: this.$store.state.options.order_select, // 订单状态下拉选框信息
        value: '',
        langFlag: true,
      },{
        type: 'rangePicker',
        label: 'public.CreateDate',
        attr: 'searchTime',
        value: [],
      },{
        type: 'select',
        attr: 'regDevice',
        label: 'add.no7',
        option: this.$store.state.options.loanDevice_options, // 借款客户端,
        value: '',
        langFlag: true,
      },
      {
        type: 'select',
        attr: 'regChannel',
        label: 'public.registerChannel',
        option: [],
        value: '',
        langFlag: false,
      },
      {
        type: 'select',
        attr: 'appName',
        label: 'public.appName',
        option: [],
        value: '',
        langFlag: false,
      },{
        type: 'select',
        attr: 'appPackage',
        label: 'public.appPackage',
        option: [],
        value: '',
        langFlag: false,
      },
      this.$route.name=='loanlists'?{
        type: 'select',
        attr: 'partnerId',
        label: 'proManage.partnerName',
        option: [], //商户名称
        value: '',
        langFlag: false,
      }:''
    ]
    return {
      routename:this.$route.name,
      flag: true,
      loadFlag: true,
      pagination: {
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      searchTime: [], // 查询时间
      searchData:searchData,
      formInline: { // 用户查询信息数据对应字段
        id:'',
        userId:'',
        userName:'',
        status:'',
        createTimeBegin:'',
        createTimeEnd:'',
        regDevice:'',
        regChannel:'',
        appName:'',
        appPackage:''
      },
      currentPage: 1, // 当前页下标
      tableData: [], // 借款信息数据模拟
      putExcelUrl:this.$action.loan_loanExport

    }
  },
  methods: {
    handleSizeChange (val) {// 每页条数变化时操作
      this.pagination.pageSize = val;
      this.getTableData();
    },
    handleCurrentChange (val) { // 分页按钮点击操作
      this.pagination.current = val;
      this.getTableData();
    },
    search (search) { // 点击查询按钮
      this.formInline=search;
      this.formInline.createTimeBegin=search.searchTime?search.searchTime[0]:'';
      this.formInline.createTimeEnd=search.searchTime?search.searchTime[1]:'';
      this.currentPage = 1;
      this.getTableData();
    },
    loanDetali(orderId, userId) { // 查看详情操作
      this.$router.push({
        path: '/loandetail',
        query: {
          userId,
          orderId
        }
      })
    },
    getTableData() { // 获取借款列表
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination.current,
        pageSize:this.pagination.pageSize,
        param: {
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.loan_loanList, option).then(res => {
        this.flag = true;
        this.loadFlag = false;
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.pagination.total = res.data.total;
        } else {
          this.$message.error(res.message);
        }
      })
    },
    download(url) { // 印尼版合同下载
      let goUrl=this.$action.fileDownload+url;
      window.location.href = goUrl;
    }
  },
  mounted() {
    this.getApp().then(app=>{
      this.searchData[8].option=app.appName;
      this.searchData[9].option=app.appPackage;
    })
    this.getChannel().then(channel=>{
      this.searchData[7].option=channel;
    })
    if(this.$route.name=='loanlists'){
      this.getMerchant().then(arr=>{
        this.searchData[10].option=arr;
      })
    }
    this.getTableData(); // 获取借款列表
  }
}
</script>
<style scoped lang="scss">

</style>